home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / cuj1008.zip / 1008054C < prev    next >
Text File  |  1991-05-10  |  8KB  |  239 lines

  1. /*****************************************************************************
  2. *                                                                            *
  3. *  File:      SCAD.C                                                         *
  4. *                                                                            *
  5. *  The code is written in Microsoft C Version 5.1, Large Model.              *
  6. *                                                                            *
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <math.h>
  13. #include <malloc.h>
  14.  
  15. #include <wm.h>
  16. #include <graphics.h>
  17. #include <halo.h>
  18.  
  19. #include "dlcodes.h"
  20.  
  21.  
  22. /*******************************************************************************
  23. *  Window Toolkit data objects                                                 *
  24. *******************************************************************************/
  25.  
  26. /* the background window structure : */
  27. WINDOW Background =
  28.     {
  29.     { 0,                        /* Exclusive                        */
  30.       0,                        /* Redrawable                       */
  31.       0,                        /* SubWindow                        */
  32.       0,                        /* Opened                           */
  33.       1,                        /* Accept Key                       */
  34.       0,                        /* Invisable                        */
  35.       0,                        /* Moving                           */
  36.       0 },                      /* Not Used                         */
  37.     { 0, 0, 0, 0 },             /* window shape and position        */
  38.     BgMessage,                  /* background message function      */
  39.     NULL,                       /* this window has no parent        */
  40.     };
  41.  
  42. /* Local global variables */
  43. static int     moveit = FALSE;
  44.  
  45. /*************** Application Global Variables *******************************/
  46.  
  47.  
  48. void Init_globals()
  49. {
  50.     FILE *fc;
  51.     int i, red, green, blue;
  52.     int func, err;
  53.     float f;
  54.  
  55.     cursortype = CUR_PLUS;
  56.     LineType = 1;
  57.     LineWidth = 1;
  58.     Text_height = 1;
  59.     Text_path = 0;
  60.  
  61.     dl_free();
  62. }
  63.  
  64.  
  65. void main (int argc, char *argv[])
  66. {
  67.     read_cnf(argc, argv);
  68.     WmInitialize (argc, argv);
  69.     Init_globals();
  70.     WindowManager (&Background);
  71.     GmDisplayClose ();
  72. }
  73.  
  74.  
  75. /*****************************************************************************
  76. *  redraw -- Redraw display list
  77. *****************************************************************************/
  78.  
  79. void redraw ()
  80. {
  81.     int xi, yi;
  82.  
  83.     /* Clear the screen and draw the display list */
  84.     setcolor (&colors[Back_color]);
  85.     clr();
  86.     dl_run();
  87. }
  88.  
  89.  
  90. /*------------------------------------------------------------------------
  91. | BgMessage
  92. |       Background window message processor.
  93. |       Handle messages from the HWT kernel and from child windows.
  94. |       Since all other windows are decended from the background window,
  95. |       this function is essentially the main function of the application.
  96. |       Messages come as a set of three parameters. The first parameter is
  97. |       the message ID, a simple integer defined in wm.h. The second parameter
  98. |       is the Window Handle to this window which allows multiple instances
  99. |       of a window to be handle by one code segment (not used here). The
  100. |       third parameter is a pointer to some data which is specific to the
  101. |       type of message being sent.
  102. |-------------------------------------------------------------------------*/
  103.  
  104. int BgMessage (int MessageID, WINDOW *Window, void *Argument)
  105. {
  106.     static CIRCLE circle;
  107.     static RECTANGLE Rect;
  108.     int xor;
  109.     int lt;
  110.     int x1, x2, y1, y2;
  111.  
  112.     switch (MessageID)
  113.         {
  114.         /*-----------------------------------------------------
  115.         | Kernel messages to the background
  116.         |------------------------------------------------------*/
  117.  
  118.         case WMsg_Open:              /* Initialization message */
  119.         WmAlwaysHideCsr ();
  120.         CmdBarWin = WmOpenCmdBar (Window, CommandBarDef, CB_SIZE (CommandBarDef));
  121.         WmSetCsrColor (CUR_PLUS, WIN_WHITE);
  122.         WmSetCsrSizeAbs (CUR_PLUS, 100, 100);
  123.         WmSetCsr (cursortype);
  124.         setcolor (&colors[Back_color]);
  125.         clr();
  126.         WmShowCsr ();
  127.         break;
  128.  
  129.         case WMsg_Move:        /* Mouse Moved, check for rubberbanding  */
  130.         if (!First_point)
  131.             switch (Pick_Mode)
  132.                 {
  133.                 case DR_TEXT:    /* XOR text to move it around */
  134.                 case ED_MOVE:
  135.                 xorobj();
  136.                 break;
  137.  
  138.                 case DR_POLYGN:    /* Draw XOR line from last point to cursor */
  139.                 case DR_POLYLN:
  140.                 case DR_FPOLY:
  141.                 movabs (&Mouse.x, &Mouse.y);
  142.                 rlnabs (&PickCorners.x1, &PickCorners.y1);
  143.                 break;
  144.                 }
  145.         break;
  146.  
  147.         case WMsg_RightDn:                /* Right button pressed */
  148.         if (!First_point)
  149.             {
  150.             WmAlwaysHideCsr ();
  151.             switch (Pick_Mode)
  152.                 {
  153.                 case DR_POLYGN:    /* end polyline drawing */
  154.                 case DR_POLYLN:
  155.                 case DR_FPOLY:
  156.                 close_poly();
  157.                 break;
  158.  
  159.                 case DR_RECT:    /* Cancel drawing a rectangle */
  160.                 case DR_FRECT:
  161.                 delbox ();
  162.                 break;
  163.                 }
  164.             WmShowCsr ();
  165.             }
  166.         First_point = TRUE;
  167.         break;
  168.  
  169.         case WMsg_LeftDn:                /* Pick button pressed */
  170.         GmSetColor (colors[Draw_color]);
  171.         WmAlwaysHideCsr ();
  172.         if (First_point)
  173.             {
  174.             switch (Pick_Mode)
  175.                 {
  176.                 case ED_MOVE:    /* move the object at the cursor */
  177.                 moveit = FALSE;
  178.                 mx = Mouse.x + 8;
  179.                 my = Mouse.y + 8;
  180.                 objend = Disp_List;
  181.                 move_obj();
  182.                 break;
  183.  
  184.                 case DR_POLYLN:    /* Picked the first vertex */
  185.                 case DR_POLYGN:
  186.                 case DR_FPOLY:
  187.                 Poly_count = 0;
  188.                 PickCorners.x1 = Mouse.x;
  189.                 PickCorners.y1 = Mouse.y;
  190.                 locx = PickCorners.x1;
  191.                 locy = PickCorners.y1;
  192.                 First_point = FALSE;
  193.                 break;
  194.                 }
  195.             }
  196.         else
  197.             {
  198.             switch (Pick_Mode)
  199.                 {
  200.                 case ED_MOVE:
  201.                 if (moveit)    /* object moving now */
  202.                     {
  203.                     del_obj();        /* draw over the original position */
  204.                     mx = Mouse.x;    /* with backgroubd color */
  205.                     my = Mouse.y;
  206.                     moveobj (select);
  207.                     }
  208.                 objdraw (select);    /* draw object in new position */
  209.                 cursortype = CUR_BOX;
  210.                 WmSetCsr (cursortype);
  211.                 moveit = FALSE;
  212.                 First_point = TRUE;
  213.                 break;
  214.  
  215.                 case DR_POLYLN:
  216.                 case DR_POLYGN:
  217.                 case DR_FPOLY:
  218.                 delln ();
  219.                 PickCorners.x2 = Mouse.x - PickCorners.x1;
  220.                 PickCorners.y2 = Mouse.y - PickCorners.y1;
  221.                 Xarray[Poly_count] = PickCorners.x2;
  222.                 Yarray[Poly_count++] = PickCorners.y2;
  223.                 movabs (&PickCorners.x1, &PickCorners.y1);
  224.                 lnrel (&PickCorners.x2, &PickCorners.y2);
  225.                 PickCorners.x1 = Mouse.x;
  226.                 PickCorners.y1 = Mouse.y;
  227.                 break;
  228.                 }
  229.             }
  230.         WmShowCsr ();
  231.         break;
  232.  
  233.         default:                    /* Message was NOT handled            */
  234.         return (FALSE);
  235.         }
  236.  
  237.     return (TRUE);                  /* Message WAS handled                */
  238. }
  239.